package com.zl.data.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import com.zl.data.config.DataConstant;

/**
 * @author ZL @朱林</a>
 * @Version 1.0
 * @Description TODO
 * @date 2021/01/08  15:40
 */
public class DataBeanInfo {
    public static final String TABLE_NAME = "data_store";

    public static final String ID = "_id";
    public static final String KEY = "key";
    public static final String VALUE = "value";

    public static final Uri CONTENT_URI = Uri.withAppendedPath(DataConstant.AUTHORITY_URI, TABLE_NAME);

    public static Uri getContentUri() {
        return CONTENT_URI;
    }

    public static ContentValues putValues(DataBean data) {
        ContentValues values = new ContentValues();
        values.put(KEY, data.getKey());
        values.put(VALUE, data.getValue());
        return values;
    }

    public static DataBean getValues(Cursor cursor) {
        int id = cursor.getInt(cursor.getColumnIndex(ID));
        String key = cursor.getString(cursor.getColumnIndex(KEY));
        byte[] value = cursor.getBlob(cursor.getColumnIndex(VALUE));
        DataBean dataBean = new DataBean(id, key, value);
        return dataBean;
    }
}
